#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
using namespace std;
class Solution1 {
public:
    int uniquePaths(int m, int n) {
        vector<vector<int>> dp(m + 1, vector<int>(n + 1));
        dp[0][1] = 1;
        for (int i = 1; i <= m; i++)
        {
            for (int j = 1; j <= n; j++)
            {
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
            }
        }

        return dp[m][n];
    }
};

class Solution2 {
public:
    int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
        int m = obstacleGrid.size(), n = obstacleGrid[0].size();
        vector<vector<int>> dp(m + 1, vector<int>(n + 1));
        vector<vector<int>> nums(m + 1, vector<int>(n + 1));
        for (int i = 1; i <= m; i++)
        {
            for (int j = 1; j <= n; j++)
            {
                nums[i][j]= obstacleGrid[i-1][j-1];

            }
        }
        
        if (nums[m][n] == 1) return 0;
        dp[0][1] = 1;
        for (int i = 1; i <= m; i++)
        {
            for (int j = 1; j <= n; j++)
            {
                if (nums[i - 1][j] == 0)
                {
                    dp[i][j] += dp[i - 1][j];
                }
                if (nums[i][j-1] == 0)
                {
                    dp[i][j] += dp[i][j - 1];
                }
                
            }
        }
        return dp[m][n];
    }
};
#include<algorithm>
class Solution {
public:
    int jewelleryValue(vector<vector<int>>& frame) {
        int m = frame.size(), n = frame[0].size();
        vector<vector<int>> dp(m+1, vector<int>(n+1));
        vector<vector<int>> nums(m + 1, vector<int>(n + 1));
        for (int i = 1; i <= m; i++)
        {
            for (int j = 1; j <= n; j++)
            {
                nums[i][j] = frame[i - 1][j - 1];

            }
        }
        for (int i = 1; i <= m; i++)
        {
            for (int j = 1; j <= n; j++)
            {
                dp[i][j] = max(dp[i - 1][j] + nums[i ][j], dp[i][j - 1] + nums[i][j ]);
            }
        }

        return dp[m][n];
    }
};

int main()
{
    vector<vector<int>> nums = { {1,3,1},{1,5,1},{4,2,1} };
    Solution s;
    cout << s.jewelleryValue(nums);
}